package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.Collect;
import com.qf.lanzhou.blog.api.pojo.entity.Praise;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.PraiseArticleService;
import com.qf.lanzhou.blog.api.service.impl.PraiseArticleServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author jian
 * @Date 2020/12/21 11:21
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/praiseArticle.do")
public class PraiseArticleServlet extends BaseServletPost{
        private PraiseArticleService praiseArticleService=new PraiseArticleServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决请求的乱码
        req.setCharacterEncoding("utf-8");
        //解决响应乱码
        resp.setContentType("text/html;charset=utf-8");

        User user1 = (User) req.getSession().getAttribute("user");
        Long id = user1.getId();
        //转为string类型
        String userId = id + "";
        //String userId = req.getParameter("userId");

        List<Praise>list= praiseArticleService.selectArticle(userId);
        System.out.println(list);
        ArrayList<Object> list1 = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            Praise praise = list.get(j);
            String articleId = praise.getArticleId();
            list1.add(articleId);

        }
        System.out.println(list1);
        successResultWrite(list1,resp);
    }
}
